package baiwa.rta.action.room;


import baiwa.rta.action.BaseAction;
import baiwa.rta.action.user.*;
import baiwa.rta.service.CarCardService;

import static baiwa.rta.action.BaseAction.lookupBean;
import static com.opensymphony.xwork2.Action.SUCCESS;

import java.util.LinkedHashMap;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Namespaces;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.json.annotations.JSON;


@Namespaces(value = {
    @Namespace("/room")
})
@ParentPackage(value = "json-default")
public class RM002JsonAction extends BaseAction {

    private static final Logger logger = Logger.getLogger(RM001JsonAction.class);
    private LinkedHashMap<String, Object> jsonData = new LinkedHashMap<>();

    private CarCardService carCardService = lookupBean(CarCardService.class, "CarCardService");

    public String execute() throws Exception {
        logger.info("USR001JsonAction Home.");
        return SUCCESS;
    }

    @Action(value = "/getAllCarCard", results = {
        @Result(name = SUCCESS, type = "json", params = {"root", "jsonData"})
    })
    public String listAllCarCard() throws Exception {
        logger.info("## " + this.getClass().getSimpleName());

        jsonData.clear();
        jsonData.put("data", carCardService.getAllCarCard());
//        jsonData.put("data", carCardService.getAllMapCarCard());

        return SUCCESS;
    }

    @JSON(name = "jsonData")
    public LinkedHashMap<String, Object> getJsonData() {
        return jsonData;
    }

}
